using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace NPC.Enemy
{
    [CreateAssetMenu(menuName = "Data/State/Boss/BossHurt", fileName = "BossHurt")]
    public class BOSSState_Hurt : BOSSState
    {
        /****动画检测*****/
        float stateStartTime; // 动画开始时间
        [SerializeField] private string stateName; // 动画名字
        [SerializeField, Range(0, 1)] private float transitionDuration = 0.1f; // 动画间过渡时间
        private int stateHash; // 动画状态的Hash值

        private bool isAnimationFinished =>
            stateDuration >= agent.Animator.GetCurrentAnimatorStateInfo(0).length; //当前动画是否播放完毕

        private float stateDuration => Time.time - stateStartTime; // 动画播放的当前时间
        public override void Enter()
        {
            base.Enter();
            stateHash = Animator.StringToHash(stateName);
            agent.Animator.CrossFade(stateHash, transitionDuration);
            stateStartTime = Time.time;
        }

        public override void Exit()
        {
            base.Exit();
            BossManager.Instance.IsHurting = false;
        }

        public override void LogicUpdate()
        {
            base.LogicUpdate();
            
            // 动画播放完成，返回
            if(isAnimationFinished)
                stateMachine.SwitchState(stateMachine.stateTable[typeof(BOSSState_HTN)]);
        }

        public override void PhysicalUpdate()
        {
            base.PhysicalUpdate();
        }
    }
}
